package com.flbill.mapper;

import com.flbill.pojo.dto.CategoryDTO;
import com.flbill.pojo.vo.ClassVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClassMapper {
    @Select("select * from expense_class")
    List<ClassVO> listExpense();

    @Select("select * from income_class")
    List<ClassVO> listIncome();
    
    /**
     * 添加支出分类
     */
    @Insert("insert into expense_class(class_id, class_name) values(0, #{class_name})")
    @Options(useGeneratedKeys = true, keyProperty = "class_id")
    void addExpenseClass(String class_name);
    
    /**
     * 添加收入分类
     */
    @Insert("insert into income_class(class_id, class_name) values(0, #{class_name})")
    @Options(useGeneratedKeys = true, keyProperty = "class_id")
    void addIncomeClass(String class_name);
    
    /**
     * 修改支出分类
     */
    @Update("update expense_class set class_name = #{class_name} where class_id = #{id}")
    void updateExpenseClass(Integer id, String class_name);
    
    /**
     * 修改收入分类
     */
    @Update("update income_class set class_name = #{class_name} where class_id = #{id}")
    void updateIncomeClass(Integer id, String class_name);
    
    /**
     * 删除支出分类
     */
    @Delete("delete from expense_class where class_id = #{id}")
    void deleteExpenseClass(Integer id);
    
    /**
     * 删除收入分类
     */
    @Delete("delete from income_class where class_id = #{id}")
    void deleteIncomeClass(Integer id);
    
    /**
     * 根据ID查询支出分类
     */
    @Select("select * from expense_class where class_id = #{id}")
    ClassVO getExpenseClassById(Integer id);
    
    /**
     * 根据ID查询收入分类
     */
    @Select("select * from income_class where class_id = #{id}")
    ClassVO getIncomeClassById(Integer id);
}
